package com.dongchao.authserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Description
 * @Author: zhaodongchao
 * @Company: datong
 * @Date: 2018-08-28
 * @Email: zhaodc@dtinsure.com
 */
@SpringBootApplication
public class AuthServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AuthServerApplication.class, args);
    }

   /* @Autowired
    OAuth2ClientContext oauth2ClientContext;

  *//*  @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.antMatcher("/**")
                .authorizeRequests()
                .antMatchers("/", "/login**", "/webjars/**", "/error**","/user")
                .permitAll()
                .anyRequest()
                .authenticated()
                .and().logout().logoutSuccessUrl("/").permitAll()
                .and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .and().addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);;
    }*//*

     *//**
     * 1	All requests are protected by default
     * 2	The home page and login endpoints are explicitly excluded
     * 3	All other endpoints require an authenticated user
     * 4	Unauthenticated users are re-directed to the home page
     * @param http
     * @throws Exception
     *//*
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http.antMatcher("/**")
              .authorizeRequests()
              .antMatchers("/", "/login**", "/webjars/**").permitAll()
              .anyRequest().authenticated()
              .and().exceptionHandling()
              .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")) ;
  }


    *//**
     * to complete the authentication it needs to know where the user info endpoint is in Facebook
     * @return
     *//*
    @Bean
    @ConfigurationProperties(prefix = "facebook")
    public ResourceServerProperties facebookResource() {
        return new ResourceServerProperties();
    }

    *//**
     * 使用@EnableOAuth2Client注解后，会默认在容器中添加OAuth2ClientContextFilter的实例。
     * 此方法的意义是给这个filter一个合适的order
     *
     * We autowire the already available filter, and register it with a sufficiently low order that it comes before the main Spring Security filter.
     * In this way we can use it to handle redirects signaled by expceptions in authentication requests
     * @param filter
     * @return
     *//*
    @Bean
    public FilterRegistrationBean oauth2ClientFilterRegistration(OAuth2ClientContextFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(filter);
        registration.setOrder(-100);
        return registration;
    }

    @Bean
    @ConfigurationProperties("github.resource")
    public ResourceServerProperties githubResource() {
        return new ResourceServerProperties();
    }
    @Bean
    @ConfigurationProperties("github")
    public ClientResources github() {
        return new ClientResources();
    }

    @Bean
    @ConfigurationProperties("facebook")
    public ClientResources facebook() {
        return new ClientResources();
    }
    private Filter ssoFilter() {
        CompositeFilter filter = new CompositeFilter();
        List<Filter> filters = new ArrayList<>();
        filters.add(ssoFilter(facebook(), "/login/facebook"));
        filters.add(ssoFilter(github(), "/login/github"));
        filter.setFilters(filters);
        return filter;
    }
    private Filter ssoFilter(ClientResources client, String path) {
        OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(path);
        OAuth2RestTemplate template = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext);
        filter.setRestTemplate(template);
        UserInfoTokenServices tokenServices = new UserInfoTokenServices(
                client.getResource().getUserInfoUri(), client.getClient().getClientId());
        tokenServices.setRestTemplate(template);
        filter.setTokenServices(tokenServices);
        return filter;
    }
    class ClientResources extends AuthorizationCodeResourceDetails {

        @NestedConfigurationProperty
        private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();

        @NestedConfigurationProperty
        private ResourceServerProperties resource = new ResourceServerProperties();

        public AuthorizationCodeResourceDetails getClient() {
            return client;
        }

        public ResourceServerProperties getResource() {
            return resource;
        }
    }*/
}

